package gitdemo1.git3.day01;

public class Sort {


    //选择排序
    public static void chose(int arr[]){
        if (arr.length==0){
            return;
        }
        for (int i = 0; i < arr.length-1; i++) {
            int index=arr[i];
            for (int j = i+1; j < arr.length; j++) {
                if (index>arr[j]){
                    swap(arr,i,j);
                }
            }
        }

    }

    //插入排序
    public static void inserSort(int arr[]){
        if(arr==null||arr.length<2){
            return;
        }
        for (int i = 1; i < arr.length; i++) {
            for (int j = i-1; j>=0&&arr[j]>arr[j+1]; j--) {
                swap(arr, j, j+1);
            }
        }
    }



    private static void swap(int[] arr, int i, int j) {
        int temp=arr[i];
        arr[i]=arr[j];
        arr[j]=temp;
    }
}
